<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Awesome-pyecharts</title>
    <script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.min.js"></script>
    <script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>

</head>
<body>
    <form method="post" action="/demo/reg/">
<!--        {% csrf_token %}-->
        username   <input type="text" name="username" value="{{data.username}}"
                          placeholder="your username"><br>
        password   <input type="text" name="password" value="{{data.password}}"
                          placeholder="your password"><br>
                   <input type="submit" value="upgrade"><br>
    </form>
<!--    {% for key, value in data.items %}-->
<!--    {{ key }} : {{ value }}<br>-->
<!--    {% endfor %}-->
    <div id="bar" style="width:1000px; height:600px;"></div>
    <script>
        var chart = echarts.init(document.getElementById('bar'), 'white', {renderer: 'canvas'});
        var old_data = [];
        $(
            function () {
                fetchData(chart);
                setInterval(fetchData, 2000);
            }
        );

        function fetchData() {
            $.ajax({
                type: "GET",
                url: "http://127.0.0.1:8001/demo/line",
                dataType: 'json',
                success: function (result) {
                    var options = result.data;
                    chart.setOption(options);
                    old_data = chart.getOption().series[0].data;
                }
            });
        }

        function getDynamicData() {
            $.ajax({
                type: "GET",
                url: "http://127.0.0.1:8001/demo/lineUpdate",
                dataType: 'json',
                success: function (result) {
                    var options = result.data;
                    old_data.push([options.name, options.value]);
                    chart.setOption({
                        series: [{
                            data: old_data
                        }]
                    });
                }
            });
        }
    </script>
</body>
</html>